<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:c="http://java.sun.com/jsp/jstl/core"
	xmlns:p="http://primefaces.org/ui" 
	template="/templates/layout.xhtml">
		
	<ui:define name="head"></ui:define>

	<ui:define name="ptitle">销售出库单管理</ui:define>
	
	<ui:define name="pcontent">	    
	<h:form id="frm1">
		<p:growl id="msgs1" showDetail="true" />
		<p:panel id="contPanel" header="【第一步】基本信息录入【在录入信息后一定要保存后再进行其他后续操作】" style="margin-bottom:5px">		
			<h:panelGrid columns="4" cellspacing="10">		
				<p:commandButton value="新增出库单" icon="ui-icon-plus" 
	           		process="@this" update=":frm1 :frm2:rdt :frmAttach"
                 	actionListener="#{saleoutMB.onAdd}" />	
				<p:commandButton value="保存出库单"	icon="ui-icon-check" 
					action="#{saleoutMB.saveAction}" update=":frm1:msgs1">
				</p:commandButton>				
			</h:panelGrid>
			
			<h:panelGrid columns="10" cellspacing="10" >	
				<p:outputLabel value="出库单编号" />
				<p:inputText  value="#{saleoutMB.io.id}" required="true" requiredMessage="出库单编号必须输入"/>

				<p:outputLabel value="出库日期" />
				<p:calendar id="signDate" locale="zh" navigator="true"  value="#{saleoutMB.io.outDate}" 
					pattern="yyyy-MM-dd" mask="true"  mode="popup"	showOn="button" popupIconOnly="true"
					required="true" requiredMessage="发货日期必须输入" />
										
				<p:outputLabel value="合同ID" />
				<p:selectOneMenu value="#{saleoutMB.selectedContract}" converter="bmeContractConverter" 
						effect="fade"  style="width:80%" panelStyle="width:180px" 
                        var="t" filter="true" filterMatchMode="startsWith"
                        required="true" requiredMessage="合同名称必须输入" 
                        converterMessage="合同信息不能正确转换">
                    <p:ajax listener="#{saleoutMB.onSelectedContract}" update=":frm1:pcontract :frm1:pproject :frm1:pcustomer :frm1:paddress" />     
					<f:selectItem itemLabel="选择..." itemValue="" noSelectionOption="true"  />
		            <f:selectItems value="#{saleoutMB.bmeContracts}" var="scontrtacr" itemLabel="#{scontrtacr.id}" itemValue="#{scontrtacr}" />
		 
		            <p:column style="width:10%">
		                <h:outputText value="#{t.id}" />
		            </p:column>		 
		            <p:column>
		                <h:outputText value="#{t.name}" />
		            </p:column>        
		        </p:selectOneMenu>
				<p:outputLabel value="项目名称" />
				<p:inputText id="pproject" value="#{acceptionMB.selectedContract.pname}"  readonly="true"  disabled="true"/>

				<p:outputLabel value="合同名称" />
				<p:inputText id="pcontract" value="#{saleoutMB.selectedContract.name}"  readonly="true"  disabled="true"/>

				<p:outputLabel value="客户名称" />
				<p:inputText id="pcustomer" value="#{saleoutMB.selectedContract.custName}" />	

				<p:outputLabel value="收货地址" />
				<p:inputText id="paddress" value="#{saleoutMB.selectedContract.shippingAddress}" />	
											
				<p:outputLabel value="金额" />
				<p:inputText id="pamount" value="#{saleoutMB.io.amount}" />	

				<p:outputLabel value="单据状态" />
				<p:selectOneMenu value="#{saleoutMB.io.status}" effect="fold" style="width:80%;" 
					required="true" requiredMessage="状态必须输入" disabled="true">
					<f:selectItem itemLabel="选择..." itemValue="" noSelectionOption="true"  />
					<f:selectItems value="#{saleoutMB.itemsStatus}" /> 
				</p:selectOneMenu>	
				<p:outputLabel value="备注" />
				<p:inputText value="#{saleoutMB.io.remarks}" />	
									
			</h:panelGrid>

		</p:panel>

	</h:form>
	<h:form id="frmAttach" > 	
		<p:growl id="msgsAttach" showDetail="true" />		
		<p:panel id="panelAttached" header="附件信息上传" toggleable="true" toggleSpeed="500" 
			 style="margin-bottom:10px" collapsed="true"> 
			<p:ajax event="toggle" listener="#{attachUploadMB.onToggle}" update="frmAttach" />
			<!-- 页面间参数传递 -->
			<ui:include src="bme_attach_upload.xhtml">
			     <ui:param name="uploadForType" value="#{saleoutMB.uploadForType}" />
			     <ui:param name="uploadForId" value="#{saleoutMB.uploadForId}" />
			     <ui:param name="uploadForName" value="#{saleoutMB.uploadForName}" />
			</ui:include>
        </p:panel>	
	</h:form>

	<h:form id="frm2">	
		<p:growl id="msgs2" showDetail="true" />
		<p:panel id="mainPanel" header="【第二步】详细信息录入" style="margin-bottom:5px">
	
			<h:panelGrid id="detailGrid" columns="10" cellspacing="10" >					
				<p:commandButton id="detailBtn" value="选择合同产品物料..."  type="button" icon="fa fa-fw fa-search-plus" onclick="PF('ovpl2').loadContents();" />
				<p:commandButton value="生成出库金额/数量"	icon="ui-icon-check" 
					action="#{saleoutMB.commitAction}" update=":frm2:msgs2  :frm1:pamount" >
				</p:commandButton>
			</h:panelGrid>

			<!-- 选择合同产品 -->
		    <p:overlayPanel  widgetVar="ovpl2" for="detailBtn" hideEffect="fade" dynamic="true" 
		   				showCloseIcon="false" style="width:1000px"  >
		       <p:dataTable var="srow" value="#{saleoutMB.bmeContProds}"  
		        	paginator="true" paginatorPosition="bottom" emptyMessage="没有记录"
		         	selection="#{saleoutMB.selectedContProds}" rowKey="#{srow.id}">
		         	
			       <p:column selectionMode="multiple" style="width:16px;text-align:center"/>  	
		           <p:column headerText="物料编号">
		               <h:outputText value="#{srow.bmeMaterial.id}" />
		           </p:column>
		           <p:column headerText="物料名称">
		               <h:outputText value="#{srow.bmeMaterial.mdesc}" />
		           </p:column>
		           <p:column headerText="规格">
		               <h:outputText value="#{srow.speci}" />
		           </p:column>		           
		           <p:column headerText="数量">
		               <h:outputText value="#{srow.quantity}" />
		           </p:column>
		           <p:column headerText="加工规格">
		               <h:outputText value="#{srow.processSpeci}" />
		           </p:column>		           
		           <p:column headerText="数量片">
		               <h:outputText value="#{srow.processQuantity}" />
		           </p:column>		           
		           <p:column headerText="单价">
		               <h:outputText value="#{srow.price}" />
		           </p:column>
		           <p:column headerText="金额">
		               <h:outputText value="#{srow.amount}" />
		           </p:column>
	
		       </p:dataTable>
		       <h:panelGrid columns="3" cellspacing="10">					  
					<p:commandButton value="确认"	icon="ui-icon-check"  oncomplete="PF('ovpl2').hide();" 
						action="#{saleoutMB.saveDetail}" update=":frm2 :frm1:pamount " >
					</p:commandButton>	
				</h:panelGrid>
		    </p:overlayPanel>
			
			<p:dataTable id="rdt" value="#{saleoutMB.vod}"  var="row"  rowIndexVar="rowNum"
				resizableColumns="true" liveResize="true" 
				editable="true"  style="margin-bottom:5px"
				paginator="true" paginatorPosition="bottom" rows="8" 
				emptyMessage="没有记录" >

				<p:ajax event="rowEdit" listener="#{saleoutMB.onRowEdit}" 
					update=":frm2:msgs2 :frm1:pamount " />
				<p:ajax event="rowEditCancel"	listener="#{saleoutMB.onRowCancel}"
					update=":frm2:msgs2" />					
				<p:column headerText="No." width="20" >
					#{rowNum+1}
				</p:column>				
				<p:column headerText="物料编号" sortBy="#{row.bmeMaterial.id}" width="100" >
					<h:outputText value="#{row.bmeMaterial.id}"  />
				</p:column>
				<p:column headerText="物料描述" width="100" >
					<h:outputText value="#{row.bmeMaterial.mdesc}" />
				</p:column>
				<p:column headerText="规格" width="100" >
					<h:outputText value="#{row.speci}" />
				</p:column>			
							
				<p:column headerText="数量" width="100" >
					<p:cellEditor>
						<f:facet name="output"><h:outputText value="#{row.mquantity}" /></f:facet>
						<f:facet name="input"><p:inputText value="#{row.mquantity}"  /></f:facet>
					</p:cellEditor>
				</p:column>
				<p:column headerText="数量片" width="100" >
					<p:cellEditor>
						<f:facet name="output"><h:outputText value="#{row.processQuantity}" /></f:facet>
						<f:facet name="input"><p:inputText value="#{row.processQuantity}"  /></f:facet>
					</p:cellEditor>
				</p:column>
				<p:column headerText="单价" width="100" >
					<p:cellEditor>
						<f:facet name="output"><h:outputText value="#{row.mprice}" /></f:facet>
						<f:facet name="input"><p:inputText value="#{row.mprice}" />
						</f:facet>
					</p:cellEditor>
				</p:column>
				<p:column headerText="金额" width="100" >
					<p:cellEditor>
						<f:facet name="output"><h:outputText value="#{row.amount}" /></f:facet>
						<f:facet name="input"><p:inputText value="#{row.amount}" />
						</f:facet>
					</p:cellEditor>
				</p:column>
				<p:column headerText="加工规格" width="100" >
					<h:outputText value="#{row.processSpeci}" />
				</p:column>
				<p:column headerText="加工工艺" width="100" >
					<h:outputText value="#{row.processTeck}" />
				</p:column>					
				<p:column headerText="备注" width="100" >
					<p:cellEditor>
						<f:facet name="output"><h:outputText value="#{row.remarks}" /></f:facet>
						<f:facet name="input"><p:inputText value="#{row.remarks}" />
						</f:facet>
					</p:cellEditor>
				</p:column>				
				
				<p:column headerText="修改" style="width:32px">
					<p:rowEditor editTitle="修改" cancelTitle="取消" saveTitle="保存" />
				</p:column>
				<p:column headerText="删除" style="width:32px">
					<p:commandButton icon="ui-icon-minus"   title="删除"  immediate="true"
						action="#{saleoutMB.delDetail}" update=":frm2 :frm1:pamount">
						<f:setPropertyActionListener value="#{row}"
							target="#{saleoutMB.selectedd}" />
						<p:confirm header="确认" message="你确定删除此记录信息？" icon="ui-icon-alert" />
					</p:commandButton>	
				</p:column>
				
			</p:dataTable>    
		</p:panel>		
	</h:form>	
		
	<!-- confirm to del product -->
    <p:confirmDialog global="true" showEffect="fade" hideEffect="fade">
        <p:commandButton value="确认" type="button" styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
        <p:commandButton value="取消" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
    </p:confirmDialog>
    
	</ui:define>
</ui:composition>
